package com.wanggsx.library.base.views;

import android.content.Context;
import androidx.annotation.Nullable;
import android.util.AttributeSet;

import com.wanggsx.library.util.UtilsLog;

/**
 *  Created by {wanggsx} on 2017/4/19
 */

public class DelayedClickTextView extends androidx.appcompat.widget.AppCompatTextView {

    public void setTime(long time) {
        this.time = time;
    }

    private long time;


    public DelayedClickTextView(Context context) {
        super(context);
        setTime(600L);
    }

    public DelayedClickTextView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        setTime(600L);
    }

    public DelayedClickTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        setTime(600L);
    }

    @Override
    public boolean performClick() {

        setClickable(false);
        postDelayed(new Runnable() {
            @Override
            public void run() {
                try {
                    setClickable(true);
                } catch (Exception e) {
                    UtilsLog.e("连续点击按钮触发异常");
                }
            }
        }, time);
        return super.performClick();
    }


}
